<!-- @format -->
<template>
  <section>
    <div class="progress_details_wrap">
      <div class="ling-flex status-details" v-if="identity=='user'">
        <div class="time-status">
          <time>2019-12-25</time>
          <span>已接单</span>
        </div>
        <div class="check-btn">
          <span
            class="ling-linearButton"
            @click="$router.push({ 
              path: '/userprogressReport', 
              query: { userJobReportDetail: JSON.stringify(userJobReportDetail), type:'edit' } 
            })"
          >编辑</span>
          <span class="ling-linearPinkButton" @click="handleDelete">删除</span>
        </div>
      </div>

      <figure>
        <p>{{ userJobReportDetail.description }}</p>
        <div
          class="img-box"
          v-for="item in userJobReportDetail.reportAnnexList"
          :key="item.id"
          :style="{ backgroundImage: `url(${item.annexUrl})` }"
          @click="showImagePopup(item.annexUrl)"
        ></div>
      </figure>
    </div>
    <van-popup v-model="showImage" closeable>
      <div class="business_license">
        <img :src="popupAnnexUrl" alt />
      </div>
    </van-popup>
  </section>
</template>

<script>
import { mapState as rootState } from 'vuex'
import { mapActions as rootActions } from 'vuex'
import { getIdentity } from '@/utils/userAuth'
import { createNamespacedHelpers } from 'vuex'
const { mapState, mapActions } = createNamespacedHelpers('myData')
export default {
  name: 'Homepage',
  data() {
    return {
      showImage: false,
      popupAnnexUrl: '',
      identity: getIdentity()
    }
  },
  props: {
    userJobReportId: {
      required: true
    }
  },
  components: {},
  computed: {
    ...rootState(['userJobReportDetail'])
  },
  created() {
    this.getUserJobReportDetail(this.userJobReportId)
  },
  methods: {
    ...rootActions(['getUserJobReportDetail']),
    ...mapActions(['deleteUserJobReport']),
    showImagePopup(annexUrl) {
      this.showImage = true
      this.popupAnnexUrl = annexUrl
    },
    handleDelete() {
      this.$dialog
        .confirm({
          title: '确认删除该进度汇报吗？',
          message: '删除不会影响当前服务进度'
        })
        .then(() => {
          this.deleteUserJobReport({ userJobReportId: this.userJobReportId })
          this.$router.push(`/haveTaskDetail`)
        })
    }
  }
}
</script>

<style lang="less" scoped>
.progress_details_wrap {
  padding: 20px;
  figure {
    display: flex;
    flex-wrap: wrap;
    p {
      width: 100%;
      font-size: 14px;
      margin-bottom: 10px;
      color: #666;
    }
    .img-box {
      width: 100px;
      height: 75px;
      background: #dbf2ff;
      margin-bottom: 10px;
      margin-right: 17px;
      background-size: cover;
    }
    .img-box:nth-child(4),
    .img-box:nth-child(7),
    .img-box:nth-child(10) {
      margin-right: 0;
    }
  }
  .status-details {
    padding: 5px 0 10px;
    .time-status {
      display: flex;
      flex-direction: column;
      font-size: 14px;
      line-height: 25px;
      time {
        color: #333;
      }
      span {
        color: #7ac5ef;
      }
    }

    .check-btn {
      span {
        width: 60px;
        height: 30px;
        display: inline-block;
        line-height: 30px;
        color: white;
        font-size: 12px;
        margin-left: 16px;
      }
    }
  }
}
</style>
